<?php
if ( !defined('IN_ADMINCP') || !defined('IN_SEC') ){
	exit('Access Denied.');
}

$admins = parse_array(limitquery('admincp_member'));

$status = customer_status();
$demands = customer_demand();
$sources = customer_source();
$natures = customer_nature();

$begin_time = strtotime("last Sunday +1 day");
$end_time = strtotime("next Sunday");
#---------------------客户统计---------------------#

$customers = limitquery('customer', $where);
$customers_datas = array();
$weeks = array(
	'星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期日'
);
foreach( $customers as $k => $v ){
	$w = date('w', $v['create_time']);
	$customers_datas[$v['nature'] ? $v['nature'] : '_none'][$w]++;
}
#---------------------最新客户---------------------#
$where = array(
	'`adminid` > 0'
);

$status_class = array(
	'label-info arrowed-right arrowed-in', 'label-danger arrowed', 'label-warning arrowed arrowed-right', 'label-success arrowed-in arrowed-in-right'
);
$new_customers = limitquery('customer', $where, array('order' => 'ORDER BY `id` DESC'), 0, 10);

$counts = array();
$counts['customer']['total'] = DB::Count('customer');
$counts['team']['total'] = DB::Count('team');
$counts['customer_contacts']['total'] = DB::Count('customer_contacts');

$customer_contacts = limitquery('customer_contacts', array(), array('order' => 'ORDER BY `id` DESC'), 0, 20);
#---------------------业务摘要---------------------#
$todays = array();

$date = date('Y-m-d');
$end_time = strtotime(date('Y-m-d', strtotime("{$date} +1 day")));
$begin_time = strtotime($date);

$todays['counts']['customer']['today']['counter'] = DB::Count('customer', array("`create_time` >= {$begin_time}", "`create_time` <= {$end_time}"), '', 'adminid');
$todays['counts']['customer']['total']['counter'] = DB::Count('customer', array(), '', 'adminid');

$todays['counts']['customer_contact']['today']['counter'] = DB::Count('customer_contacts', array("`create_time` >= {$begin_time}", "`create_time` <= {$end_time}"), '', 'adminid');
$todays['counts']['customer_contact']['total']['counter'] = DB::Count('customer_contacts', array(), '', 'adminid');

foreach( $todays['counts'] as $k => $v ){
	foreach( $v as $pkname => $pkcounter ){
		foreach( $pkcounter as $tdk => $tdv ){
			foreach( $tdv as $dk => $dv ){
				$todays['datas'][$k][$pkname][$dv['adminid']] = $dv['count'];
			}
		}
	}
}
unset($todays['counts']);
$todays['admins'] = limitquery('admincp_member', array('departmentid' => 3));
//print_r($todays);
$remark = &$admincp->remark;
?>